<%@page import="cn.sendto.mapper.IRowMapper"%>
<%@page import="cn.sendto.dbhelper.DBHelper"%>
<%@page import="cn.sendto.mapper.*" %>
<%@page import="cn.sendto.model.*" %>
<%@page import="java.util.List" %>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
   if(request.getSession().getAttribute("user")==null){
	   request.getRequestDispatcher("login.jsp").forward(request, response);
   }

%>
<html>
	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="css/global.css"/>
		<title>添加成绩</title>
		<link rel="stylesheet" href="css/main.css" />
       <title></title>
      </head>
	<body class="add">
		<div class="add_div">
			<form action="do_addscore.jsp" method="post">
			<%
			   request.setCharacterEncoding("UTF-8");
			
			   String id = request.getParameter("id");
			   DBHelper helper =new DBHelper();
			   final String QUREYCOURSE ="select * from courseinfo where courseid=?";
			   IRowMapper mapper1 = new CourseMapper();
			   
			   List<CourseEntity> list1= helper.executeQuery(QUREYCOURSE, mapper1, id);
			   
			%>
			    <div class="add_item">
					<span>课程名称：</span>
					<input type="text" readonly="readonly" value="<%=list1.get(0).getCourseName() %>"/>
				</div>
				<input type="hidden" name="courseid" value="<%=list1.get(0).getCourseId()%>"/>
				<div class="add_item">
					<span>学生姓名：</span>
					<select name="studentid">
						<%
						
						String sql ="select * from studentinfo";
						String sql2="select studentid from scoreinfo where courseid=?";
						StudentMapper StudentMapper = new StudentMapper();
						ScoreMapper scoreMapper=new ScoreMapper();
						List<StudentEntity> list = helper.executeQuery(sql, StudentMapper, null);
						List<ScoreEntity> list2=  helper.executeQuery(sql2, scoreMapper, id);
						for(int i =0;i<list.size();i++){
							if(list2.size()==0){
								out.print("<option value='"+list.get(i).getStudentId()+"'>"+list.get(i).getStudentName()+"</option>");
							} else{
								for(int j=0;j<list2.size();j++){
									if(list.get(i).getStudentId().equals(list2.get(j).getStudentId())){
										break;
									}
									if(j==list2.size()-1){
										out.print("<option value='"+list.get(i).getStudentId()+"'>"+list.get(i).getStudentName()+"</option>");
									}
								}
							
							}
							
						}
						%>
					</select>
				</div>
				<div class="add_item">
					<span>课程成绩：</span>
					<input type="text" name="score" />
				</div>

				<div class="btn">
					<input  type="submit" value="添加"/>
				</div>
			</form>
		</div>
	</body>
</html>